<template>
  <div class="card-head">
    <div class="card-title">
      <svg-icon :icon-class="icon" style="margin-right: 3px"></svg-icon>{{ title }}
    </div>
    <div class="card-head-btns">
      <TimePicker></TimePicker>
      <el-button class="icon-btn" @click="handleInit"
        ><i class="el-icon-refresh" style="font-weight: bold; font-size: 16px"></i
      ></el-button>
      <el-button class="icon-btn" @click="handleInfo"
        ><i class="el-icon-info" style="font-size: 16px"></i
      ></el-button>
      <el-button class="icon-btn" @click="handleDownload"
        ><svg-icon icon-class="download" style="font-size: 16px"></svg-icon
      ></el-button>
    </div>
    <el-dialog
      :visible.sync="dialogVisible"
      width="500px"
      custom-class="analysis-info"
      :title="info.title"
    >
      <div class="info-item" v-for="(item, index) in info.listInfo">
        <div>{{ item.title }}</div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import TimePicker from "@/components/XyTimePicker";
export default {
  name: "CardHead",
  props: {
    title: {
      type: String,
      default: "",
    },
    icon: {
      type: String,
      default: "",
    },
    info: {
      type: Object,
      default: () => {},
    },
  },
  components: {
    TimePicker,
  },
  data() {
    return {
      dialogVisible: false,
    };
  },
  methods: {
    handleInfo() {
      this.dialogVisible = true;
    },
    handleDownload() {
      // 触发自定义事件，通知父组件执行下载操作
      this.$emit("download-chart");
    },
    handleInit() {
      this.$emit("init-chart");
    },
  },
};
</script>
<style scoped lang="scss">
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 0;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(0, 102, 255, 0.1);
  .card-title {
    font-size: 20px;
    color: #0066ff;
    font-weight: 600;
  }
  .card-head-btns {
    display: flex;
    align-items: center;
    .icon-btn {
      margin-left: 10px;
      width: 38px;
      height: 38px;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 10px;
      cursor: pointer;
      transition: all 0.3s;
      border: 1px solid rgba(0, 102, 255, 0.15);
      background-color: rgba(0, 102, 255, 0.08);
      color: #0066ff;
      padding: 0;
    }
    .icon-btn:hover {
      background: #0066ff;
      color: white;
      transform: scale(1.1);
      box-shadow: 0 4px 15px rgba(0, 102, 255, 0.3);
    }
  }
}
</style>
<style lang="scss">
.el-dialog.analysis-info {
  margin-top: 20vh !important;
  .el-dialog__header {
    font-size: 1.4rem;
    font-weight: 600;
    background-color: #fff;
    border-bottom: 1px solid rgba(0, 102, 255, 0.1);
    padding: 20px;
    .el-dialog__title {
      color: #0066ff !important;
    }
  }
  .el-dialog__body {
    padding: 20px;
    background-color: #fff;
    margin-top: 0;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    .info-item {
      line-height: 1.7;
      color: #64748b;
      font-size: 0.9rem;
    }
  }
}
</style>
